package com.byzk.invoice.xml.Doc_0;

import com.byzk.invoice.util.DocumentUtil;
import org.dom4j.*;

import java.io.File;

/**
 * 创建Document.xml.
 *
 * @author 康鹏 2020-05-20
 */
public class DocumentXml {

    /**
     * 创建Doc_0/Document.xml.
     * @param documentXmlPath Document.xml存放路径
     * @throws Exception Exception
     */
    public static void createDocumentXml(String documentXmlPath) throws Exception {

        Namespace namespace = new Namespace("ofd", "http://www.ofdspec.org/2016");
        //创建外层<ofd:Res />
        Element rootElt = DocumentHelper.createElement(new QName("Document", namespace));
        //创建<ofd:CommonData />
        Element commonDataElt = rootElt.addElement("ofd:CommonData");
        Element maxUnitIDElt = commonDataElt.addElement("ofd:MaxUnitID");
        maxUnitIDElt.setText("139");
        Element templatePageElt = commonDataElt.addElement("ofd:TemplatePage");
        templatePageElt.addAttribute("ID", "2");
        templatePageElt.addAttribute("BaseLoc", "Tpls/Tpl_0/Content.xml");
        Element pageAreaElt = commonDataElt.addElement("ofd:PageArea");
        Element physicalBoxElt = pageAreaElt.addElement("ofd:PhysicalBox");
        physicalBoxElt.setText("0 0 210 140");
        Element publicResElt = commonDataElt.addElement("ofd:PublicRes");
        publicResElt.setText("PublicRes.xml");
        Element documentResElt = commonDataElt.addElement("ofd:DocumentRes");
        documentResElt.setText("DocumentRes.xml");
        //创建<ofd:Pages />
        Element pagesElt = rootElt.addElement("ofd:Pages");
        Element pageElt = pagesElt.addElement("ofd:Page");
        pageElt.addAttribute("ID", "1");
        pageElt.addAttribute("BaseLoc", "Pages/Page_0/Content.xml");
        //创建<ofd:Annotations />
        Element annotationsElt = rootElt.addElement("ofd:Annotations");
        annotationsElt.setText("Annots/Annotations.xml");
        //创建<ofd:Attachments />
        Element attachmentsElt = rootElt.addElement("ofd:Attachments");
        attachmentsElt.setText("Attachs/Attachments.xml");
        //创建<ofd:CustomTags />
        Element customTagsElt = rootElt.addElement("ofd:CustomTags");
        customTagsElt.setText("Tags/CustomTags.xml");


        Document document = DocumentHelper.createDocument(rootElt);
        DocumentUtil.writer(document, documentXmlPath + File.separator + "Doc_0"
                + File.separator + "Document.xml", true);
    }

}
